package ygg.encoding.swf.tag.codec
{
	import j.sus2maj7.encoding.*;
	import j.sus2maj7.context.*;
	import flash.utils.ByteArray;
	
	import ygg.encoding.swf.tag.*;
	import ygg.encoding.swf.tag.object.*;
	import ygg.encoding.swf.structure.*;
	
	
	public class DefineBitsLosslessCodec extends TagCodec
	{
		public function DefineBitsLosslessCodec()
		{
			super();
		}
		
		override public function decode(binary:IBinary, context:IContext=null):*
		{
			var retVal:DefineBitsLossless = new DefineBitsLossless();
			var b:TagBinary = binary as TagBinary;
			b.position = 0;
			b.syncBits();
			
			retVal.characterId = b.readU16();
			retVal.bitmapFormat = b.readU8();
			retVal.bitmapWidth = b.readU16();
			retVal.bitmapHeight = b.readU16();
			
			if (retVal.bitmapFormat == BitmapFormat.COLOR_MAPPED_8)
			{
				retVal.bitmapColorTableSize = b.readU8();
				
			}
				/*
				bytes.uncompress();
				
				var bytesInput:DataInput = new ByteArrayInputStream(bytes);
				var table:Array = tag.colorTable;
				
				if (table.length != colorTableSize)
				{
					table.length = colorTableSize;
				}
				
				for (var i:uint = 0; i < colorTableSize; ++i) {
					table[i] = readRGB(bytesInput, context);
				}
				
				b.readBytes(tag.data);
				
			}
			else // BitmapFormat.RGB_15 or 24
			{
				b.readBytes(retVal.zlibBitmapData);
				//tag.data.uncompress();
				
			}*/
			
			var bytes:ByteArray = new ByteArray();
			b.readBytes(bytes);
			retVal.zlibBitmapData = new TagBinary(bytes);
			
			return retVal;
		}
		
		override public function encode(o:*, context:IContext=null):IBinary
		{
			var b:TagBinary = new TagBinary();
			var obj:DefineBitsLossless = o as DefineBitsLossless;
			
			
			
			return b;
		}
	}
}